package com.redhipps.hips.client.io;

import com.redhipps.hips.client.model.Context;
import com.redhipps.hips.client.model.PythonDatastoreKey;
import com.redhipps.hips.client.model.Model;

public interface IOService {

  <T extends Model> ModelReader<T> reader(Class<?> modelClass);

  <T extends Model> ModelWriter<T> writer(Class<?> modelClass);

  /**
   * Loads prototypes of the given model type and context.
   * 
   * @param callback Called on completion.
   */
  <T extends Model> void list(Context context, Class<T> modelClass,
      final ReaderCallback<T> callback);

  /**
   * Fully loads one instance of the given model.
   * 
   * @param key Key for model to load.
   * @param callback Called on completion.
   */
  <T extends Model> void read(Context context, Class<T> modelClass,
      PythonDatastoreKey key, final ReaderCallback<T> callback);

  /**
   * Creates a new model in the datastore using the given prototype and calls the
   * callback with a fully formed model based on the prototype.
   * <p>
   * Potentially creates a model tree with the given root. The descendants of the
   * root are created on the server side to avoid multiple calls to create a complex
   * tree.
   * 
   * @param context
   * @param modelPrototype
   * @param callback
   */
  <T extends Model> void create(Context context, T modelPrototype, WriterCallback<T> callback);

  /**
   * Writes an existing model to the datastore. Does a shallow write of the given model only.
   * TODO Bulk updates.
   * 
   * @param context
   * @param model
   * @param callback
   */
  <T extends Model> void write(Context context, T model, WriterCallback<T> callback);

}
